package com.zhouyu.tool;

import com.zhouyu.service.User;
import com.zhouyu.seven.OrderServiceSeven;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;

import java.util.Collections;
import java.util.Set;

// TODO 这个转换方法再看
public class StringToOrderServiceSevenConverter implements ConditionalGenericConverter {

	@Override
	public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
		return sourceType.getType().equals(String.class) && targetType.getType().equals(User.class);
	}

	@Override
	public Set<ConvertiblePair> getConvertibleTypes() {
		return Collections.singleton(new ConvertiblePair(String.class, User.class));
	}

	@Override
	public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
		OrderServiceSeven orderServiceSeven = new OrderServiceSeven();
		orderServiceSeven.setName((String) source);
		return orderServiceSeven;
	}

}
